home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Algorithms for Image Analysis
/
Practical Algorithms for Image Analysis.iso
/
TARFILE.GZ
/
tarfile
/
ch_4.3
/
xcc
/
test_xcc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-11
|
2KB
|
102 lines
/*
* test_xcc.c
*
* Practical Algorithms for Image Analysis
*
* Copyright (c) 1997 1997, 1998, 1999 MLMSoftwareGroup, LLC
*/
/*
* TEST_XCC.C
*
* routines to support test mode of xcc.c:
* the test mode dispenses with image I/O and relies on appropriate
* data representing sets of edge tuples, supplied in a data file,
* test_xcc.tpl
*
*/
#include "xcc.h"
/*
* io error handling
*/
int
io_err (char *string, int retval)
{
printf ("...%s:", string);
printf (" error reading file\n");
return (retval);
}
/*
* read first line in data file to determine size of record
*/
int
fetch_test_parms (FILE * file, float *dsk_dia, int *del_ir, int *nch, int *ir_base)
{
int retval;
if (((retval = fscanf (file, "%f", dsk_dia)) == 0) || (retval == EOF))
io_err ("FETCH_TEST_PARMS", 0);
if (((retval = fscanf (file, "%d", del_ir)) == 0) || (retval == EOF))
io_err ("FETCH_TEST_PARMS", 0);
if (((retval = fscanf (file, "%d", nch)) == 0) || (retval == EOF))
io_err ("FETCH_TEST_PARMS", 0);
if (((retval = fscanf (file, "%d", ir_base)) == 0) || (retval == EOF))
io_err ("FETCH_TEST_PARMS", 0);
return (1);
}
/*
* read test data in the form of edge tuples on a given row (scan line)
* edge tuple test data in the form {cl, cr} are contained in the data
* file (generally of type .tpl) for a set of consecutive scan lines,
* (spaced at del_ir);
* the edge tuples for each row are given in the form of a group of
* tuples {cl, cr} preceeded by the nof tuples in the group;
* the top of the file contains, in order: dsk_dia (type float);
* del_ir (type int);
* ir_base (type int);
*/
int
fetch_test_row (FILE * file, struct linklist *etll)
{
int ie, ne;
int row;
int retval;
struct edge_tuple cur_etpl, *cetpl = &cur_etpl;
if (((retval = fscanf (file, "%d %d", &ne, &row)) == 0) || (retval == EOF))
io_err ("FETCH_TEST_ROW", 0);
printf ("\n...fetch %d edge tuples for row %d\n", ne, row);
llhead (etll);
cetpl->cl = cetpl->cr = -1;
cetpl->status = UnMatched;
for (ie = 0; ie < ne; ie++) {
retval = fscanf (file, "%d %d", &(cetpl->cl), &(cetpl->cr));
if ((retval == 0) || (retval == EOF))
io_err ("FETCH_TEST_ROW", 0);
cetpl->status = Matched;
/* enter new ON-segm into edge_tuple_list */
lladd ((char *) cetpl, etll);
}
return (ne);
}